#ifndef _RETRO_TILESELECTOR
#define _RETRO_TILESELECTOR

namespace Retro
{
  namespace Creator
  {
    namespace GUI
    {
      enum TileTool
      {
        TileToolSelect = 0x0001,
        TileToolDirection,
        TileToolFlags,
      };

      enum TileNotify
      {
        TileNotifySelection = 0x0001,
        TileNotifyEdit,
        TileNotifyErase,
      };

      class TileSelector : public Component
      {
      private:
        INT                 mTileSize;
        Geom::Bounds        mSelection;
        Geom::Point         mDragPoint;
        Geom::Point         selectedTile;
        BOOL                mMouseDown;
        Gdiplus::Bitmap*    wBuffer;
        ScrollInfo          scroll;
        BOOL                erase;
        Data::Texture*      mTexture;
        TileTool            mTool;
        TCHAR               mTileInfo[100];

        Gdip::Font          mFont;
        Gdip::SolidBrush    mBrush;
        Gdip::Pen           mPen;
        Gdip::StringFormat  mFormat;

        VOID  adjustMousePos(Geom::Point& pt);
        INT   calcScrollPos(INT sbRequest, INT nBar, INT current);

        VOID  drawTile(LONG x, LONG y, Gdip::Graphics& g);
        VOID  drawArrow(
          Gdip::PointF (&iArrow)[POINT_COUNT_ARROW],
          BOOL iSelected,
          Gdip::Graphics& g);

        VOID  getArrowBounds(
          Gdip::RectF& iSource,
          Gdip::RectF& oBounds,
          Geom::Direction iDirection
          );

        VOID  invalidateTile(LONG x, LONG y);

      protected:
        VOID  onSize(Event::SizeEvent& iEvent);
        VOID  onHScroll(Event::ScrollEvent& iEvent);
        VOID  onVScroll(Event::ScrollEvent& iEvent);
        VOID  onEraseBackground(Event::EraseBackgroundEvent& iEvent);
        VOID  onPaint();
        VOID  onMouseDown(Event::MouseEvent& iEvent);
        VOID  onMouseUp(Event::MouseEvent& iEvent);
        VOID  onMouseMove(Event::MouseEvent& iEvent);
        VOID  onMouseLeave();
        VOID  onMouseWheel(Event::MouseWheelEvent& iEvent);
        VOID  onKeyDown(Event::KeyEvent& iEvent);
        VOID  onFocus(Event::FocusEvent& iEvent);

      public:
        VOID  setTexture(Data::Texture* iValue);

        INL Data::Texture* getTexture()
        {
          return mTexture;
        }

        VOID  setSelection(const Geom::Bounds& value);

        INL TileTool getTool()
        {
          return mTool;
        }

        VOID      setTool(TileTool iValue);

        INL BOOL  getErase()
        {
          return erase;
        }
        VOID      setErase(BOOL value);

        INLC Geom::Bounds&  getSelection()
        {
          return mSelection;
        }

        TileSelector();
        ~TileSelector();
      };
    } // namespace GUI
  } // namespace Creator
} // namespace Retro

#endif
